const app = getApp()
Page({
    data:{
        motto: null,
        height:null,
        weight:null,
        bni:0,
        message:null
    },
    onLoad() {
        var self = this
        console.log(app.globalData.name)
        console.log(app.globalData.passwd)
        wx.request({
            url: 'http://127.0.0.1:8080/getBNI',
            method:'POST',
            
            data:{
                name:app.globalData.name
            },
            success(res) {
              console.log(res.data)
                self.setData({
                  bni:res.data
                })
                self.getMessage()
               
            }
    
          })
      },
      getMessage(){
         if(this.data.bni <= 0) {
             this.setData({
                 message:'请输入你的身高体重，获取你的健康系数'
             })
         }
         else if(this.data.bni<18.4){
            this.setData({
                message:'你过于消瘦，需要多运动与摄入营养'
            })
         }
         else if(this.data.bni<23.9){
            this.setData({
                message:'你很健康，请继续保持良好的生活饮食习惯'
            })
         }
         else if(this.data.bni<27.9){
            this.setData({
                message:'你有点超重，要加强锻炼哦'
            })
         }
         else{
            this.setData({
                message:'科学减肥和足够的运动对你而言是必须的'
            })
         }
      },
      submit(){
        var self = this
        console.log(app.globalData.name)
        console.log(app.globalData.passwd)
        wx.request({
            url: 'http://127.0.0.1:8080/updateBNI',
            method:'POST',
            
            data:{
                name:app.globalData.name,
                height:self.data.height,
                weight:self.data.weight
            },
            success(res) {
              console.log(res.data)
                self.setData({
                  bni:res.data
                })
                self.getMessage()
               
            }
    
          })
      },
      getHeight(e){
        this.setData({
            height:e.detail.value
        })
      },
      getWeight(e){
          this.setData({
              weight:e.detail.value
          })
      }

})

